package com.flyme.module.base.provider.service.impl;

import com.flyme.common.core.model.ResultBody;
import com.flyme.core.base.supper.service.impl.BaseServiceImpl;
import com.flyme.module.base.client.entity.SysSlider;
import com.flyme.module.base.provider.mapper.SysSliderMapper;
import com.flyme.module.base.provider.service.SysSliderService;
import com.flyme.module.file.client.constants.FileConstants;
import javafx.scene.control.Slider;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: zyf
 * @date: 2018/10/24 16:33
 * @description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysSliderServiceImpl extends BaseServiceImpl<SysSliderMapper, SysSlider> implements SysSliderService {

    @Override
    public Boolean add(SysSlider slider) {
        slider.setSendStatus(FileConstants.LIVE_PUB);
        return save(slider);
    }


    @Override
    public Boolean edit(SysSlider slider) {
        return saveOrUpdate(slider);
    }

    @Override
    public ResultBody delByIds(String[] ids) {
        remove(q().in("id", ids));
        return ResultBody.success("刪除成功");
    }

    /**
     * 查找轮播图
     */
    @Override
    public List<SysSlider> selectSliders(Integer type, Integer sliderType) {
        return list(q().eq("sendStatus", type).eq("sliderType", sliderType));
    }

    /**
     * 根据类型查询轮播图
     */
    public Integer countByType(Integer sliderType){
        return count(q().eq(true, "sliderType", sliderType));
    }
    /**
     * 查询单个图片
     */
    @Override
    public SysSlider selectOne(Integer type, Integer sliderType){
        return getOne(q().eq("sendStatus",type).eq("sliderType", sliderType), false);
    }

}
